package com.godme.rabbitmq.controller;


import com.godme.rabbitmq.bean.Product;
import com.godme.rabbitmq.repo.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/product")
public class ProductController {


    @Autowired
    ProductRepository productRepository;

    @GetMapping("/goods")
    public ModelAndView goodsList(){
        return new ModelAndView("goods", "goods", productRepository.findAll());
    }


    @GetMapping("/add")
    public ModelAndView addProduct(@RequestParam("productName") String productName, @RequestParam("residue") int residue){
        Product product = new Product();
        product.setResidue(residue);
        product.setName(productName);
        productRepository.addProduct(product);
        return goodsList();
    }




}
